// 导入Vue
import Vue from 'vue'
// 导入路由
import Router from 'vue-router'
// 安装路由
Vue.use(Router)
// 导入布局组件
/* Layout */
import Layout from '@/layout'
// 导入动态路由
import syssetting from './modules/systemSetting'
import vipmange from './modules/vipManage'
import contenmange from './modules/contenMange'
import idsmange from './modules/IdsMange'
// 路由的一些自定义配置

// 动态路由
export const asyncRoutes = [syssetting, contenmange, idsmange, vipmange]

// 静态路由
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        name: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        meta: { title: '后台首页', icon: 'dashboard' }
      }
    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]
// 创建路由的方法
const createRouter = () =>
  new Router({
    // mode: "history", // require service support
    // mode表示路由模式，默认是hash模式，如果要设置成history模式上线的时候是需要后端进行配置设置
    // 如果设置history，上线之后要让后端区分好哪个是前端路由，哪个是后端路由，否则会冲突
    scrollBehavior: () => ({ y: 0 }),
    // routes: [...constantRoutes, ...asyncRoutes], // 静态路由+动态路由 配置放在一起
    routes: [...constantRoutes, ...asyncRoutes] // 静态路由配置
  })
// 调用，得到一个路由实例对象
const router = createRouter()

// 重置路由的方法
// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter () {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}
// 暴露
export default router
